package model;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JPanel;


public class dessin {

	int X;
	int Y;
	Color color=new Color(0,0,0);
	
	public dessin()
	{
		
	}
	
	public void coordonnees(MouseEvent ev)
	{
		if(!ev.isMetaDown()) // si c'est pas un clique droit
		{
			X=ev.getX();
			Y=ev.getY();
			
		}
	
	}
	
	public static void ajouterCode(String code )  throws IOException
	{
				int i = 0;
				int cont=0;
				FileWriter writer = null;
				
				boolean p=true;
				//enlever les 0 de debut
				while(p)
				{
					if(code.charAt(i) != '1')
					{
						i++;
					}
					if(code.charAt(i) == '1')
					{
						p=false;
					}
						
				}
				String t=code.substring(i);
				i=t.length()-1;
				//enlever les 0 de la fin
				while(t.charAt(i) == '0')
				{
					cont++;
					i--;
				}
				String texte=t.substring(0,(t.length()-cont))+"\n";
				
				texte=code+"\n";
				
				
				try{
				     writer = new FileWriter("C:/Users/PC-Web-intelligence/workspaceKepler/projetApprentissage/src/view/code.txt", true);
				     writer.write(texte,0,texte.length());
				}
				catch(IOException ex){
				    ex.printStackTrace();
				}
				finally{
				  if(writer != null){
				     writer.close();
				  }
				}
		
	}
	
	
	    
}
